package com.cike.sparkstudy.basescala

object ConditionalControlAndLoop {
  def main(args: Array[String]): Unit = {
    /*val age = 19
    val target = if(age > 18) 1 else 0
    println(target)
    var n = 10; for(i <- 1 to n) println(i)
    var m = 10; for(j <- 1 until m) println(j)

    for (i <- 1 to 9; j <- 1 to 9) {
      if (j == 9) {
        println(i * j)
      } else {
        print(i * j + "  ")
      }
    }
    println(fab(10))*/
    //println(sayHello("zengpan"))

    val s = sum2(1,2,34,5,5)

    println(s)


  }
  def sayHello(firstName: String, middleName: String = "William", lastName: String = "Croft") = firstName + " " + middleName + " " + lastName


  def sum2(nums: Int*): Int = {
    if (nums.length == 0) 0
    else nums.head + sum2(nums.tail:_*)
  }


  def fab(n:Int):Int={
  if(n<=1) 1
  else fab(n-1)+fab(n-2)
  }

  def gameLock(): Unit = {

    val name = readLine("欢迎来到游戏厅，请输入你的名字：")

    println("你好，请输入你的年龄")
    val age = readInt()

    if (age <= 18) {
      printf("%s,你好，你的年龄是%d,游戏厅不欢迎你", name, age)
    } else {
      printf("%s,你好，你的年龄是%d,游戏厅欢迎你", name, age)
    }
  }

  //scala的方法必須給出所有的參數類型，但是不一定給出函數的返回值类型，
  // 如果方法体没有递归语句，sacla可以自己推断出类型
  def sayHello(name: String, age: Int): Unit = {
    if (age > 18) {
      printf("hi %s, you are a big boy\n", name);
    }
    else {
      printf("hi %s, you are a little boy\n", age);

    }
  }


}
